package cn.tedu._10vehicle.base.interception;

import cn.tedu._10vehicle.pojo.vo.UserVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor{
   @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
        log.debug("进入登录状态校验的拦截器。。。");
        HttpSession session = request.getSession();
        UserVO userVO = (UserVO) session.getAttribute("user");
        if(userVO == null){//未登录
            //http://localhost:8080/login.html
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }

}
